import { defineStore } from 'pinia'
import { commentGetList, commentPull } from "../../api/comment/index"
interface State {

  commentList: {
    list: Comment[],
    page_all_num: number
  }

  pullComment: pullComment

}

interface pullComment {
  "article_id": string,
  "comment_id": string,
  "content": string,
  "isMain": string
}

interface Comment {
  "create_time": string,
  "nickname": string,
  "avatar": string,
  "comment_id": string,
  "content": string,
  "follow_comments"?: Comment[]
}

export const CommentsStore = defineStore('comment', {
  //属性
  state: (): State => {
    return {
      commentList: {
        list: [],
        page_all_num: 0
      },
      pullComment: {
        "article_id": "",
        "comment_id": "",
        "content": "",
        "isMain": "1"
      }
    }
  },
  //数据处理
  getters: {


  },
  //函数
  actions: {
    //获取评论列表
    async getCommentListData(article_id: string) {
      try {
        const res: any = await commentGetList({ "article_id": article_id });
        this.commentList = res.data.data
      
      }
      catch (error) {

      }

    },
    //上传
    async pullCommentData() {
      try {
        await commentPull(this.pullComment);
       
      }
      catch (error) {

      }

    },



  },

})